package com.lanou.myapp.funny;

import android.app.ProgressDialog;
import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.lanou.myapp.R;
import com.lanou.myapp.funny.picturefunny.PictureFragment;
import com.lanou.myapp.funny.textfunny.TextFragment;
import com.lanou.myapp.funny.videofunny.VideoFragment;

import java.util.ArrayList;

/**
 * Created by dllo on 16/1/10.
 */
public class FunnyFragment extends Fragment{
    private Context context;
    private TabLayout tabLayout;
    private ViewPager viewPager;
    private FunnyFragmentAdapter adapter;
    private ArrayList<Fragment> data;


    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        this.context = context;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        tabLayout = (TabLayout) getActivity().findViewById(R.id.tabLayout_funny);
        viewPager = (ViewPager) getActivity().findViewById(R.id.viewPager_funny);

        data = new ArrayList<>();
        data.add(new TextFragment());
        data.add(new PictureFragment());
        data.add(new VideoFragment());

        adapter = new FunnyFragmentAdapter(getActivity().getSupportFragmentManager(),context,data);
        viewPager.setAdapter(adapter);
        tabLayout.setTabTextColors(Color.BLUE, Color.GREEN);
        tabLayout.setupWithViewPager(viewPager);

    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = LayoutInflater.from(context).inflate(R.layout.fragment_funny,null);
        return view;
    }
}
